//
//  RecordTableViewCell.m
//  ProjectB
//
//  Created by lanou on 16/5/11.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "RecordTableViewCell.h"
#import "Record.h"
#import "NSString+StringColor.h"

@implementation RecordTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.contentBackgroundView.layer.shadowOpacity = 1;
    self.contentBackgroundView.layer.shadowOffset = CGSizeMake(0, 2);
    self.contentBackgroundView.layer.shadowColor = [UIColor darkGrayColor].CGColor;
    self.contentBackgroundView.layer.cornerRadius = 3;
    self.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1];
}

- (void)setModel:(Record *)model {
    NSDate *fromDate = nil;
    NSDate *toDate = nil;
    [[NSCalendar currentCalendar] rangeOfUnit:NSCalendarUnitDay startDate:&fromDate interval:nil forDate:model.recordDate];
    [[NSCalendar currentCalendar] rangeOfUnit:NSCalendarUnitDay startDate:&toDate interval:nil forDate:[NSDate date]];
    NSDateComponents *dateComponents = [[NSCalendar currentCalendar] components:NSCalendarUnitDay fromDate:fromDate toDate:toDate options:0];
    
    if (dateComponents.day <= 0) {
        self.titleLabel.text = [NSString stringWithFormat:@"距离 %@", model.title];
        self.categoryLabel.text = @"还有";
        self.dateLabel.text = [NSString stringWithFormat:@" %ld 天 ", -dateComponents.day];
    } else {
        self.titleLabel.text = model.title;
        self.categoryLabel.text = @"已经";
        self.dateLabel.text = [NSString stringWithFormat:@" %ld 天 ", dateComponents.day];
    }
    
    self.dateLabel.backgroundColor = [model.backgroundColor stringColor];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
